Skip to content

test: deflake audit log subscription-event assertion (split from #1999) - #2002

Merged
kriszyp merged 2 commits into
mainfrom
kris/deflake-audit-log-events
Jul 31, 2026
Merged

test: deflake audit log subscription-event assertion (split from #1999)#2002
kriszyp merged 2 commits into
mainfrom
kris/deflake-audit-log-events

Conversation

@kriszyp

@kriszyp kriszyp commented Jul 30, 2026

Copy link
Copy Markdown
Member

Summary

Split out of #1999 per review feedback there — this test-only change is unrelated to the TLS fix and was one of the commits conflicting on the v5.1 patch cherry-pick, so it shouldn't gate a customer patch.

transactionBroadcast.ts coalesces committed bursts landing in the same turn into a single notify pass, and the subscribe() listener delivers only the latest value per id from that pass (by design). Four same-turn writes to two ids can therefore collapse to as few as 2 delivered events no matter how long the test polls afterwards. The fix waits for the notify drain after each write instead of after the whole burst, which makes delivery deterministic and lets the assertion tighten from "at least a couple" (> 2) to the true bound (>= 4, one live-subscription event per write).

Rebased onto current main, which had independently gained a partial deflake (a waitFor(> 2) block); the per-write waits supersede it, so that block is replaced by the tight assertion. Main's cleanup-pass improvements in the same test are untouched.

Testing

unitTests/resources/auditLog.test.js: 3/3 consecutive runs green (22 passing each, ~800 ms). A reviewer on #1999 also ran the original version of this change 3× with 51–69 ms completion against the 500 ms-per-write budget.

Refs #1999.

Generated by Claude (Opus 5) for dispatch task fix-harper-1999.

🤖 Generated with Claude Code

check log after writes and prune asserted events.length > 2 after polling
up to 200ms, but polling longer never helped: transactionBroadcast.ts
coalesces 'committed' bursts landing in the same turn into one notify
pass, and the subscribe() listener in Table.ts intentionally delivers
only the latest value per id from that pass. When all four writes in
this test land in one turn (as they reliably do on a fast/idle Node 22
CI runner), only 2 of the 4 events ever get delivered — they're dropped,
not delayed, so the previous fixed-then-polling deflake (ed3ec88)
could never fix it.

Wait for each write's own notify drain before issuing the next write, so
every commit gets its own turn and its own event. This makes delivery
deterministic (4/4) instead of racing the coalescing behavior.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the audit log unit test to make event delivery deterministic by waiting for the event count to increment after each write operation, replacing a single wait at the end. The reviewer suggests using the existing waitFor helper instead of implementing a custom polling loop with delay(10). Additionally, the reviewer recommends using assert.strictEqual to assert the exact event count of 4 instead of using loose inequality, aligning with the repository's style guide.

Comment thread unitTests/resources/auditLog.test.js
Comment thread unitTests/resources/auditLog.test.js
@claude

claude Bot commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Reviewed; no blockers found.

kriszyp added a commit that referenced this pull request Jul 30, 2026
Split out per review feedback to unblock the v5.1 patch cherry-pick:

- The usageType/'server'-allowlist half (server/mqtt.ts,
  server/threads/threadServer.js onSocket, LEGACY_SERVER_FALLBACK_TYPES
  in keys.ts, and its cipher-scoping test) moves to #2003. It is a
  no-op for stock deployments and was the source of the wide v5.1
  conflict, since v5.1 predates getEffectiveTlsCiphers.
- The unrelated auditLog.test.js deflake moves to #2002.

What remains here is exactly the customer-facing fix: createTLSSelector's
readiness guard/retry, the hdb_certificate subscription lifecycle
(instance tracking, teardown, failure reset), the per-row cert parse
guard, and the zero-certificates retry — plus their tests.

Co-Authored-By: Claude Opus <noreply@anthropic.com>
github-actions Bot pushed a commit that referenced this pull request Jul 30, 2026
Split out per review feedback to unblock the v5.1 patch cherry-pick:

- The usageType/'server'-allowlist half (server/mqtt.ts,
  server/threads/threadServer.js onSocket, LEGACY_SERVER_FALLBACK_TYPES
  in keys.ts, and its cipher-scoping test) moves to #2003. It is a
  no-op for stock deployments and was the source of the wide v5.1
  conflict, since v5.1 predates getEffectiveTlsCiphers.
- The unrelated auditLog.test.js deflake moves to #2002.

What remains here is exactly the customer-facing fix: createTLSSelector's
readiness guard/retry, the hdb_certificate subscription lifecycle
(instance tracking, teardown, failure reset), the per-row cert parse
guard, and the zero-certificates retry — plus their tests.

Co-Authored-By: Claude Opus <noreply@anthropic.com>
Per review: replace the hand-rolled 50x10ms poll with the repo's
waitFor helper, which throws with a clear message on a genuine
delivery failure instead of silently falling through to the final
assertion. Keeps >= semantics in both the waiter and the assertion:
the property under test is "at least one event per write," and an
overshoot should surface in the assertions below rather than hang
the waiter into its timeout.

Co-Authored-By: Claude Opus <noreply@anthropic.com>
kriszyp added a commit that referenced this pull request Jul 30, 2026
Split out per review feedback to unblock the v5.1 patch cherry-pick:

- The usageType/'server'-allowlist half (server/mqtt.ts,
  server/threads/threadServer.js onSocket, LEGACY_SERVER_FALLBACK_TYPES
  in keys.ts, and its cipher-scoping test) moves to #2003. It is a
  no-op for stock deployments and was the source of the wide v5.1
  conflict, since v5.1 predates getEffectiveTlsCiphers.
- The unrelated auditLog.test.js deflake moves to #2002.

What remains here is exactly the customer-facing fix: createTLSSelector's
readiness guard/retry, the hdb_certificate subscription lifecycle
(instance tracking, teardown, failure reset), the per-row cert parse
guard, and the zero-certificates retry — plus their tests.

Co-Authored-By: Claude Opus <noreply@anthropic.com>
github-actions Bot pushed a commit that referenced this pull request Jul 30, 2026
Split out per review feedback to unblock the v5.1 patch cherry-pick:

- The usageType/'server'-allowlist half (server/mqtt.ts,
  server/threads/threadServer.js onSocket, LEGACY_SERVER_FALLBACK_TYPES
  in keys.ts, and its cipher-scoping test) moves to #2003. It is a
  no-op for stock deployments and was the source of the wide v5.1
  conflict, since v5.1 predates getEffectiveTlsCiphers.
- The unrelated auditLog.test.js deflake moves to #2002.

What remains here is exactly the customer-facing fix: createTLSSelector's
readiness guard/retry, the hdb_certificate subscription lifecycle
(instance tracking, teardown, failure reset), the per-row cert parse
guard, and the zero-certificates retry — plus their tests.

Co-Authored-By: Claude Opus <noreply@anthropic.com>
github-actions Bot pushed a commit that referenced this pull request Jul 30, 2026
Split out per review feedback to unblock the v5.1 patch cherry-pick:

- The usageType/'server'-allowlist half (server/mqtt.ts,
  server/threads/threadServer.js onSocket, LEGACY_SERVER_FALLBACK_TYPES
  in keys.ts, and its cipher-scoping test) moves to #2003. It is a
  no-op for stock deployments and was the source of the wide v5.1
  conflict, since v5.1 predates getEffectiveTlsCiphers.
- The unrelated auditLog.test.js deflake moves to #2002.

What remains here is exactly the customer-facing fix: createTLSSelector's
readiness guard/retry, the hdb_certificate subscription lifecycle
(instance tracking, teardown, failure reset), the per-row cert parse
guard, and the zero-certificates retry — plus their tests.

Co-Authored-By: Claude Opus <noreply@anthropic.com>
github-actions Bot pushed a commit that referenced this pull request Jul 30, 2026
Split out per review feedback to unblock the v5.1 patch cherry-pick:

- The usageType/'server'-allowlist half (server/mqtt.ts,
  server/threads/threadServer.js onSocket, LEGACY_SERVER_FALLBACK_TYPES
  in keys.ts, and its cipher-scoping test) moves to #2003. It is a
  no-op for stock deployments and was the source of the wide v5.1
  conflict, since v5.1 predates getEffectiveTlsCiphers.
- The unrelated auditLog.test.js deflake moves to #2002.

What remains here is exactly the customer-facing fix: createTLSSelector's
readiness guard/retry, the hdb_certificate subscription lifecycle
(instance tracking, teardown, failure reset), the per-row cert parse
guard, and the zero-certificates retry — plus their tests.

Co-Authored-By: Claude Opus <noreply@anthropic.com>
kriszyp added a commit that referenced this pull request Jul 30, 2026
Split out per review feedback to unblock the v5.1 patch cherry-pick:

- The usageType/'server'-allowlist half (server/mqtt.ts,
  server/threads/threadServer.js onSocket, LEGACY_SERVER_FALLBACK_TYPES
  in keys.ts, and its cipher-scoping test) moves to #2003. It is a
  no-op for stock deployments and was the source of the wide v5.1
  conflict, since v5.1 predates getEffectiveTlsCiphers.
- The unrelated auditLog.test.js deflake moves to #2002.

What remains here is exactly the customer-facing fix: createTLSSelector's
readiness guard/retry, the hdb_certificate subscription lifecycle
(instance tracking, teardown, failure reset), the per-row cert parse
guard, and the zero-certificates retry — plus their tests.

Co-Authored-By: Claude Opus <noreply@anthropic.com>
github-actions Bot pushed a commit that referenced this pull request Jul 30, 2026
Split out per review feedback to unblock the v5.1 patch cherry-pick:

- The usageType/'server'-allowlist half (server/mqtt.ts,
  server/threads/threadServer.js onSocket, LEGACY_SERVER_FALLBACK_TYPES
  in keys.ts, and its cipher-scoping test) moves to #2003. It is a
  no-op for stock deployments and was the source of the wide v5.1
  conflict, since v5.1 predates getEffectiveTlsCiphers.
- The unrelated auditLog.test.js deflake moves to #2002.

What remains here is exactly the customer-facing fix: createTLSSelector's
readiness guard/retry, the hdb_certificate subscription lifecycle
(instance tracking, teardown, failure reset), the per-row cert parse
guard, and the zero-certificates retry — plus their tests.

Co-Authored-By: Claude Opus <noreply@anthropic.com>
@kriszyp
kriszyp marked this pull request as ready for review July 30, 2026 19:04
@cb1kenobi

Copy link
Copy Markdown
Member

Reviewed 55b2670 — no issues found. This PR looks good, nice job!

Note: #1993 (still open) edits the same test block (unitTests/resources/auditLog.test.js, the write-burst + subscription-event assertion in check log after writes and prune) with a different, incompatible approach — adding a third never-superseded id and content-based event assertions, vs. this PR's per-write drain. Whichever merges second will hit a merge conflict on these lines and should re-verify against the other's reasoning rather than blindly resolving it. No conflict with #1963 (already merged, and its cleanup-pass code is left untouched here).


Generated by Barber AI

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants